#include "windowInit.h"
#include "windowLogin.h"
#include "windowNewUser.h"

windowInit::windowInit(sdlScreen& screen): window::window(screen){
	this->background.load("backgroundWelcome.png");
	this->botLogin.load("botonLogin.gif");
	this->botNewUser.load("botonNewUser.gif");
	this->botQuit.load("botonQuit.gif");
	this->sndBotClick.load("botClicked.wav");
}

void windowInit::show(){
	screen.applySurface(0,0,this->background);
	int distBot = 50;
	int width = (screen.width()-botLogin.width()) /2;
	screen.applySurface(width,distBot, botLogin);
	botLogin.setPosition(width,distBot);
	distBot += botLogin.height() + 100;
	width = (screen.width()-botNewUser.width()) /2;
	screen.applySurface(width,distBot,botNewUser);
	botNewUser.setPosition(width,distBot);
	distBot += botNewUser.height() + 100;
	width = (screen.width()-botQuit.width()) /2;
	screen.applySurface(width,distBot,botQuit);
	botQuit.setPosition(width,distBot);
	this->screen.refresh();
}

bool windowInit::handleEvent(const SDL_Event& event, window*& win){
	win = NULL;
	bool b = false;
	if (event.type == SDL_MOUSEBUTTONDOWN){
		if (event.button.button == SDL_BUTTON_LEFT){
			if (this->botLogin.wasClicked(event)){
				this->sndBotClick.play();
				win = new windowLogin(screen);
				SDL_Delay(150); // Vale la espera?
				b = true;
			} else if (this->botNewUser.wasClicked(event)){
				this->sndBotClick.play();
				win = new windowNewUser(screen);
				SDL_Delay(150); // Vale la espera?
				b = true;
			} else if (this->botQuit.wasClicked(event)){
				this->sndBotClick.play();
				SDL_Event quitEvent;
				quitEvent.type=SDL_QUIT;
				SDL_PushEvent(&quitEvent);
				b = true;
			}
		} 
	}
	return b;
}

windowInit::~windowInit(){}
